﻿
namespace SwtorCalculator {
    using System;
    using System.Windows.Controls;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;

    /// <summary>
    /// Interaction logic for ItemButton.xaml
    /// </summary>
    public partial class ItemButton : UserControl {
        private string prefix = @"pack://application:,,,/SwtorCalculator;component/Images/ItemIcons/";
        private string suffix = "Empty.png";

        /// <summary>
        /// ItemButton no-arg constructor
        /// </summary>
        public ItemButton() {
            InitializeComponent();
            this.EnchantButton.ButtonOne.ToolTip = "Material";
            this.EnchantButton.ButtonTwo.ToolTip = "Modification";
            this.EnchantButton.ButtonThree.ToolTip = "Enchancement";
        }

        private string name;
        internal string SlotName {
            get { return name; }
            set {
                if( value != null ) {
                    name = value;
                    updateButton();
                    updateTooltip( name );
                }
            }
        }

        private void updateButton() {
            if( Character.EquippedItems[name].Name.ToLower() == "none" )
                ArmorButton.Button.Background = new ImageBrush( new BitmapImage( new Uri( prefix + Character.EquippedItems[name].Slot + suffix, UriKind.Absolute ) ) );
            ArmorButton.Border.Fill = getBrush();
        }

        internal void updateTooltip( string tooltip ) {
            this.ToolTip = General.wrapText( tooltip );
        }

        private SolidColorBrush getBrush() {
            switch( ( int )Character.EquippedItems[name].Quality ) {
                case 0:
                case 1:
                    return new SolidColorBrush( Colors.DimGray );
                case 2:
                    return new SolidColorBrush( Colors.White );
                case 3:
                    return new SolidColorBrush( Colors.LimeGreen );
                case 4:
                    return new SolidColorBrush( Colors.Blue );
                case 5:
                    return new SolidColorBrush( Colors.BlueViolet );
                case 6:
                    return new SolidColorBrush( Color.FromArgb( 0xFF, 0xFF, 0x77, 0x00 ) );
                default:
                    return new SolidColorBrush( Colors.DimGray );
            }
        }
    }
}
